<?php
/**
 * 版本:酷享云支付3.0版
 * 作者：余生
 * 官网：www.kuxiangcms.com
 * 技术QQ：2316803263
 * 酷享云支付官网:pay.kuxiangcms.cn
**/
//广告列表
include("../includes/common.php");
include './head.php';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
$numrows=$DB->query("SELECT * from pay_cement WHERE `active` = 1")->rowCount();
$pagesize=20;
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
{
 $pages++;
 }
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
$page=1;
}
$offset=$pagesize*($page - 1);

$rs=$DB->query("SELECT * FROM `pay_cement` WHERE `active` = 1 order by id desc limit $offset,$pagesize")->fetchAll();
 $numrows=$DB->query("SELECT count(*) from pay_cement WHERE  `active` = 1")->fetchColumn();
    $sql=" 1";
    $con='共有 <b>'.$numrows.'</b> 条广告信息';
$user="管理员";
?> 
<?php
 
if (isset($_POST['delnotice'])){
    $nid = $_POST['delnotice'];
    $sql = "DELETE FROM `pay_cement` WHERE `id` = $nid";
    if ($DB->query($sql)){
        echo "<script>alert('删除成功');window.history.go(-1);</script>";
    }
}
?>
<?php if ($_GET['my'] == 'list'){ ?>

<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a>
                    <cite>广告信息列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div> 
         <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                       <div class="layui-card-body ">
                        
                     &nbsp;&nbsp;<a href="./advertisement.php?my=add" class="layui-btn">广告添加</a>&nbsp;
                               <?php echo $con;?> 
                         
  <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                                <thead>
                                    <tr> 
                                  <th>名称</th>
                                  <th>内容</th>
                                  <th>发布时间</th>
                                  <th>跳转地址</th>
                                  <th>操作</th>
                                </thead>
                               <tbody>
                               <?php
                              foreach ($rs as $row){ ?>
                      <tr>
                        <td><?php echo $row['title'];?></td>
                        <td><?php echo mb_substr($row['content'], 0, 60, 'utf-8')?>.........<br></td>
                        <td><?php echo $row['time'];?></td>
                        <td><?php echo $row['usernane'];?></td>
                    
                        <td>
                         <form action="advertisement.php?my=list" method="post">
                                <a href="advertisement.php?my=edit&nid=<?php echo $row['id']; ?>" class="layui-btn layui-btn-normal layui-btn-sm">编辑</a>
                                <button onclick="return confirm('你确实要删除此广告吗？');" type="submit" class="layui-btn layui-btn-sm layui-btn-danger" value="<?php echo $row['id']; ?>" name="delnotice">删除</button>
                                </form>
                        </td></tr>                             
<?php  }?>
 
          </tbody>
        </table>
      </div>

        <div class="layui-card-body ">
                            <div class="page">
                                <div>

<?php
echo'<ul class="pagination">';
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo '<li><a href="advertisement.php?page='.$first.$link.'">首页</a>';
echo '<li><a href="advertisement.php?page='.$prev.$link.'">&laquo;</a></li>';
} else {
echo '<li class="disabled"><a>首页</a></li>';
echo '<li class="disabled"><a>&laquo;</a></li>';
}
for ($i=1;$i<$page;$i++)
echo '<li><a href="advertisement.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '<li class="disabled"><a>'.$page.'</a></li>';
if($pages>=10)$s=10;
else $s=$pages;
for ($i=$page+1;$i<=$s;$i++)
echo '<li><a href="advertisement.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '';
if ($page<$pages)
{
echo '<li><a href="advertisement.php?page='.$next.$link.'">&raquo;</a></li>';
echo '<li><a href="advertisement.php?page='.$last.$link.'">尾页</a></li>';
} else {
echo '<li class="disabled"><a>&raquo;</a></li>';
echo '<li class="disabled"><a>尾页</a></li>';
}
echo'</ul>';
#分页
?>
 <?php }elseif ($_GET['my'] == 'add'){
            if (isset($_POST['submit'])){
                $active =$_POST['active'] ;
                $title = $_POST['title'];
                $content = $_POST['content'];
                $time = $_POST['time'];
                $usernane = $_POST['usernane'];
                $num = $DB->query("SELECT COUNT(1) FROM `pay_cement`")->fetchColumn();
                $id = $num + 1;
                $sql = "INSERT INTO `pay_cement` (`id`,`title`,`content`,`time`,`usernane`,`active`) VALUES ($id,'$title','$content','$time','$usernane','$active');";
                if ($DB->query($sql)){
                echo "<script>alert('添加成功');window.location.href='./advertisement.php?my=list';</script>";
                }else{
                 echo "<script>alert('添加失败');window.history.go(-1);</script>";
                }
            }else{
            ?>
    <div class="layui-tab page-content-wrap layui-card">
      <ul class="layui-tab-title">
        <li class="layui-this">广告添加</li>
      </ul>
      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <form class="layui-form" action="advertisement.php?my=add" method="post">
            <div class="layui-form-item">
            <input type="hidden" name="active" value="1">
              <label class="layui-form-label">标题：</label>
              <div class="layui-input-block">
                <input type="text"  autocomplete="off" required="" placeholder="请输入广告标题" class="layui-input" name="title" value="">
              </div>
            </div>
             <div class="layui-form-item layui-form-text">
              <label class="layui-form-label">内容：</label>
              <div class="layui-input-block">
                <textarea name="content" placeholder="请输入广告内最多300字！" rows="5" class="layui-textarea" value=""></textarea>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">添加时间：</label>
              <div class="layui-input-block">
                <input type="text"  autocomplete="off" required="" class="layui-input" name="time" value="<?=$date?>">
              </div>
            </div>

             <div class="layui-form-item">
              <label class="layui-form-label">跳转地址：</label>
              <div class="layui-input-block">
                <input type="text"  autocomplete="off" required="" class="layui-input" name="usernane" value="">
              </div>
            </div>

            <div class="layui-form-item">
              <div class="layui-input-block">
              <input type="submit" name="submit" value="确认添加" class="layui-btn layui-btn-normal "/>
              </div>
            </div>
          </form>
        </div>
        </div>
        <?php }}elseif ($_GET['my'] == 'edit'){
            $nid = $_GET['nid'];
            $row = $DB->query("SELECT * FROM `pay_cement` WHERE `id` = {$nid}")->fetch();
            if ($row['id'] == ''){
                exit("<script>alert('猜猜哪里出了错误');window.history.go(-1)</script>");
            }
            if (isset($_POST['submit'])){
                $active =$_POST['active'] ;
                $title = $_POST['title'];
                $content = $_POST['content'];
                $time = $_POST['time'];
                $usernane = $_POST['usernane'];
                $url = $_POST['url'];
                $sql = "UPDATE `pay_cement` SET `title` = '$title',`content` = '$content',`time` = '$time',`usernane` = '$usernane',`active` = '$active' WHERE `id` = {$nid}";
                if ($DB->query($sql)){
                    echo "<script>alert('编辑成功！');window.location.href='./advertisement.php?my=list';</script>";
                }else{
                   echo "<script>alert('编辑失败！');window.history.go(-1);</script>";
                }
            }else{
            ?>
           <div class="layui-tab page-content-wrap layui-card">
      <ul class="layui-tab-title">
        <li class="layui-this">广告编辑</li>
      </ul>
      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <form class="layui-form" action="advertisement.php?my=edit&nid=<?=$row['id']?>" method="post">
            <div class="layui-form-item">
            <input type="hidden" name="active" value="1">
              <label class="layui-form-label">标题：</label>
              <div class="layui-input-block">
                <input type="text"  autocomplete="off" required="" placeholder="请输入广告标题" class="layui-input" name="title" value="<?=$row['title']?>">
              </div>
            </div>
             <div class="layui-form-item layui-form-text">
              <label class="layui-form-label">内容：</label>
              <div class="layui-input-block">
                <textarea name="content" placeholder="请输入广告内最多300字！" rows="5" class="layui-textarea" value=""><?=$row['content']?></textarea>
              </div>
            </div>

            <div class="layui-form-item">
              <label class="layui-form-label">添加时间：</label>
              <div class="layui-input-block">
                <input type="text"  autocomplete="off" required="" class="layui-input" name="time" value="<?=$date?>">
              </div>
            </div>

             <div class="layui-form-item">
              <label class="layui-form-label">跳转地址：</label>
              <div class="layui-input-block">
                <input type="text"  autocomplete="off" required="" class="layui-input" name="usernane" value="<?=$row['usernane']?>">
              </div>
            </div>

            <div class="layui-form-item">
              <div class="layui-input-block">
              <input type="submit" name="submit" value="确认修改" class="layui-btn layui-btn-normal "/>
              </div>
            </div>
          </form>
        </div>
        </div>
        <?php }} ?>

 <!--请勿盗卖酷享云支付源码程序 ，如发现盗卖将不提供更新服务，系统由余生网络信息提供技术服务-->
                                    
                                    
                                   </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

  <script>layui.use(['laydate', 'form'],
        function() {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });
        });
      </script>